package org.swirrel.listener;

import javax.swing.event.ChangeEvent;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.TableColumnModelEvent;
import javax.swing.event.TableColumnModelListener;

import org.swirrel.util.MethodCall;
import org.swirrel.util.SwirrelException;

/**
 * <p>Title: Swirrel</p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2009</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 0.1
 */
public class SwirrelTableColumnModelListener
    extends AbstractSwirrelListener implements TableColumnModelListener {

  private final MethodCall columnAddedCall;
  private final MethodCall columnMarginChangedCall;
  private final MethodCall columnMovedCall;
  private final MethodCall columnRemovedCall;
  private final MethodCall columnSelectionChangedCall;

  public SwirrelTableColumnModelListener(
      MethodCall columnAddedCall,
      MethodCall columnMarginChangedCall,
      MethodCall columnMovedCall,
      MethodCall columnRemovedCall,
      MethodCall columnSelectionChangedCall) {
    this.columnAddedCall = columnAddedCall;
    this.columnMarginChangedCall = columnMarginChangedCall;
    this.columnMovedCall = columnMovedCall;
    this.columnRemovedCall = columnRemovedCall;
    this.columnSelectionChangedCall = columnSelectionChangedCall;
    if (!checkSignature(columnAddedCall, TableColumnModelEvent.class) ||
        !checkSignature(columnMovedCall, TableColumnModelEvent.class) ||
        !checkSignature(columnRemovedCall, TableColumnModelEvent.class)) {
      throw new SwirrelException(
          "Method must have none or one TableColumnModelEvent argument");
    }
    if (!checkSignature(columnMarginChangedCall, ChangeEvent.class)) {
      throw new SwirrelException(
          "Method must have none or one ChangeEvent argument");
    }
    if (!checkSignature(columnSelectionChangedCall, ListSelectionEvent.class)) {
      throw new SwirrelException(
          "Method must have none or one ListSelectionEvent argument");
    }
  }

  public void columnAdded(TableColumnModelEvent e) {
    call(columnAddedCall, e);
  }

  public void columnRemoved(TableColumnModelEvent e) {
    call(columnRemovedCall, e);
  }

  public void columnMoved(TableColumnModelEvent e) {
    call(columnMovedCall, e);
  }

  public void columnMarginChanged(ChangeEvent e) {
    call(columnMarginChangedCall, e);
  }

  public void columnSelectionChanged(ListSelectionEvent e) {
    call(columnSelectionChangedCall, e);
  }
}
